package org.xwalk.core.internal;

import android.app.Activity;
import android.content.Context;
import android.content.pm.PackageManager;
import android.text.TextUtils;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.os.Process;
import android.telephony.TelephonyManager;
import android.provider.Settings;
import android.webkit.WebSettings;

import java.lang.reflect.Constructor;
import java.lang.reflect.Method;

public class XWalkSettingsBridge extends XWalkSettingsInternal {
    private XWalkCoreBridge coreBridge;
    private Object wrapper;

    public Object getWrapper() {
        return wrapper;
    }

    private ReflectMethod enumLayoutAlgorithmClassValueOfMethod = new ReflectMethod();

    private Object ConvertLayoutAlgorithmInternal(LayoutAlgorithmInternal type) {
        return enumLayoutAlgorithmClassValueOfMethod.invoke(type.toString());
    }


    private XWalkSettingsInternal internal;

    XWalkSettingsBridge(XWalkSettingsInternal internal) {
        this.internal = internal;
        reflectionInit();
    }

    @Override
    public void setCacheMode(int mode) {
        if (setCacheModeintMethod == null || setCacheModeintMethod.isNull()) {
            setCacheModeSuper(mode);
        } else {
            setCacheModeintMethod.invoke(mode);
        }
    }

    public void setCacheModeSuper(int mode) {
        if (internal == null) {
            super.setCacheMode(mode);
        } else {
            internal.setCacheMode(mode);
        }
    }

    private ReflectMethod setCacheModeintMethod = new ReflectMethod(null, "setCacheMode");

    @Override
    public int getCacheMode() {
        if (getCacheModeMethod == null || getCacheModeMethod.isNull()) {
            return getCacheModeSuper();
        } else {
            return (Integer)getCacheModeMethod.invoke();
        }
    }

    public int getCacheModeSuper() {
        int ret;
        if (internal == null) {
            ret = super.getCacheMode();
        } else {
            ret = internal.getCacheMode();
        }
        
        return ret;
    }

    private ReflectMethod getCacheModeMethod = new ReflectMethod(null, "getCacheMode");

    @Override
    public void setBlockNetworkLoads(boolean flag) {
        if (setBlockNetworkLoadsbooleanMethod == null || setBlockNetworkLoadsbooleanMethod.isNull()) {
            setBlockNetworkLoadsSuper(flag);
        } else {
            setBlockNetworkLoadsbooleanMethod.invoke(flag);
        }
    }

    public void setBlockNetworkLoadsSuper(boolean flag) {
        if (internal == null) {
            super.setBlockNetworkLoads(flag);
        } else {
            internal.setBlockNetworkLoads(flag);
        }
    }

    private ReflectMethod setBlockNetworkLoadsbooleanMethod = new ReflectMethod(null, "setBlockNetworkLoads");

    @Override
    public boolean getBlockNetworkLoads() {
        if (getBlockNetworkLoadsMethod == null || getBlockNetworkLoadsMethod.isNull()) {
            return getBlockNetworkLoadsSuper();
        } else {
            return (Boolean)getBlockNetworkLoadsMethod.invoke();
        }
    }

    public boolean getBlockNetworkLoadsSuper() {
        boolean ret;
        if (internal == null) {
            ret = super.getBlockNetworkLoads();
        } else {
            ret = internal.getBlockNetworkLoads();
        }
        
        return ret;
    }

    private ReflectMethod getBlockNetworkLoadsMethod = new ReflectMethod(null, "getBlockNetworkLoads");

    @Override
    public void setAllowFileAccess(boolean allow) {
        if (setAllowFileAccessbooleanMethod == null || setAllowFileAccessbooleanMethod.isNull()) {
            setAllowFileAccessSuper(allow);
        } else {
            setAllowFileAccessbooleanMethod.invoke(allow);
        }
    }

    public void setAllowFileAccessSuper(boolean allow) {
        if (internal == null) {
            super.setAllowFileAccess(allow);
        } else {
            internal.setAllowFileAccess(allow);
        }
    }

    private ReflectMethod setAllowFileAccessbooleanMethod = new ReflectMethod(null, "setAllowFileAccess");

    @Override
    public boolean getAllowFileAccess() {
        if (getAllowFileAccessMethod == null || getAllowFileAccessMethod.isNull()) {
            return getAllowFileAccessSuper();
        } else {
            return (Boolean)getAllowFileAccessMethod.invoke();
        }
    }

    public boolean getAllowFileAccessSuper() {
        boolean ret;
        if (internal == null) {
            ret = super.getAllowFileAccess();
        } else {
            ret = internal.getAllowFileAccess();
        }
        
        return ret;
    }

    private ReflectMethod getAllowFileAccessMethod = new ReflectMethod(null, "getAllowFileAccess");

    @Override
    public void setAllowContentAccess(boolean allow) {
        if (setAllowContentAccessbooleanMethod == null || setAllowContentAccessbooleanMethod.isNull()) {
            setAllowContentAccessSuper(allow);
        } else {
            setAllowContentAccessbooleanMethod.invoke(allow);
        }
    }

    public void setAllowContentAccessSuper(boolean allow) {
        if (internal == null) {
            super.setAllowContentAccess(allow);
        } else {
            internal.setAllowContentAccess(allow);
        }
    }

    private ReflectMethod setAllowContentAccessbooleanMethod = new ReflectMethod(null, "setAllowContentAccess");

    @Override
    public boolean getAllowContentAccess() {
        if (getAllowContentAccessMethod == null || getAllowContentAccessMethod.isNull()) {
            return getAllowContentAccessSuper();
        } else {
            return (Boolean)getAllowContentAccessMethod.invoke();
        }
    }

    public boolean getAllowContentAccessSuper() {
        boolean ret;
        if (internal == null) {
            ret = super.getAllowContentAccess();
        } else {
            ret = internal.getAllowContentAccess();
        }
        
        return ret;
    }

    private ReflectMethod getAllowContentAccessMethod = new ReflectMethod(null, "getAllowContentAccess");

    @Override
    public void setJavaScriptEnabled(boolean flag) {
        if (setJavaScriptEnabledbooleanMethod == null || setJavaScriptEnabledbooleanMethod.isNull()) {
            setJavaScriptEnabledSuper(flag);
        } else {
            setJavaScriptEnabledbooleanMethod.invoke(flag);
        }
    }

    public void setJavaScriptEnabledSuper(boolean flag) {
        if (internal == null) {
            super.setJavaScriptEnabled(flag);
        } else {
            internal.setJavaScriptEnabled(flag);
        }
    }

    private ReflectMethod setJavaScriptEnabledbooleanMethod = new ReflectMethod(null, "setJavaScriptEnabled");

    @Override
    public void setAllowUniversalAccessFromFileURLs(boolean flag) {
        if (setAllowUniversalAccessFromFileURLsbooleanMethod == null || setAllowUniversalAccessFromFileURLsbooleanMethod.isNull()) {
            setAllowUniversalAccessFromFileURLsSuper(flag);
        } else {
            setAllowUniversalAccessFromFileURLsbooleanMethod.invoke(flag);
        }
    }

    public void setAllowUniversalAccessFromFileURLsSuper(boolean flag) {
        if (internal == null) {
            super.setAllowUniversalAccessFromFileURLs(flag);
        } else {
            internal.setAllowUniversalAccessFromFileURLs(flag);
        }
    }

    private ReflectMethod setAllowUniversalAccessFromFileURLsbooleanMethod = new ReflectMethod(null, "setAllowUniversalAccessFromFileURLs");

    @Override
    public void setAllowFileAccessFromFileURLs(boolean flag) {
        if (setAllowFileAccessFromFileURLsbooleanMethod == null || setAllowFileAccessFromFileURLsbooleanMethod.isNull()) {
            setAllowFileAccessFromFileURLsSuper(flag);
        } else {
            setAllowFileAccessFromFileURLsbooleanMethod.invoke(flag);
        }
    }

    public void setAllowFileAccessFromFileURLsSuper(boolean flag) {
        if (internal == null) {
            super.setAllowFileAccessFromFileURLs(flag);
        } else {
            internal.setAllowFileAccessFromFileURLs(flag);
        }
    }

    private ReflectMethod setAllowFileAccessFromFileURLsbooleanMethod = new ReflectMethod(null, "setAllowFileAccessFromFileURLs");

    @Override
    public void setLoadsImagesAutomatically(boolean flag) {
        if (setLoadsImagesAutomaticallybooleanMethod == null || setLoadsImagesAutomaticallybooleanMethod.isNull()) {
            setLoadsImagesAutomaticallySuper(flag);
        } else {
            setLoadsImagesAutomaticallybooleanMethod.invoke(flag);
        }
    }

    public void setLoadsImagesAutomaticallySuper(boolean flag) {
        if (internal == null) {
            super.setLoadsImagesAutomatically(flag);
        } else {
            internal.setLoadsImagesAutomatically(flag);
        }
    }

    private ReflectMethod setLoadsImagesAutomaticallybooleanMethod = new ReflectMethod(null, "setLoadsImagesAutomatically");

    @Override
    public boolean getLoadsImagesAutomatically() {
        if (getLoadsImagesAutomaticallyMethod == null || getLoadsImagesAutomaticallyMethod.isNull()) {
            return getLoadsImagesAutomaticallySuper();
        } else {
            return (Boolean)getLoadsImagesAutomaticallyMethod.invoke();
        }
    }

    public boolean getLoadsImagesAutomaticallySuper() {
        boolean ret;
        if (internal == null) {
            ret = super.getLoadsImagesAutomatically();
        } else {
            ret = internal.getLoadsImagesAutomatically();
        }
        
        return ret;
    }

    private ReflectMethod getLoadsImagesAutomaticallyMethod = new ReflectMethod(null, "getLoadsImagesAutomatically");

    @Override
    public void setBlockNetworkImage(boolean flag) {
        if (setBlockNetworkImagebooleanMethod == null || setBlockNetworkImagebooleanMethod.isNull()) {
            setBlockNetworkImageSuper(flag);
        } else {
            setBlockNetworkImagebooleanMethod.invoke(flag);
        }
    }

    public void setBlockNetworkImageSuper(boolean flag) {
        if (internal == null) {
            super.setBlockNetworkImage(flag);
        } else {
            internal.setBlockNetworkImage(flag);
        }
    }

    private ReflectMethod setBlockNetworkImagebooleanMethod = new ReflectMethod(null, "setBlockNetworkImage");

    @Override
    public boolean getBlockNetworkImage() {
        if (getBlockNetworkImageMethod == null || getBlockNetworkImageMethod.isNull()) {
            return getBlockNetworkImageSuper();
        } else {
            return (Boolean)getBlockNetworkImageMethod.invoke();
        }
    }

    public boolean getBlockNetworkImageSuper() {
        boolean ret;
        if (internal == null) {
            ret = super.getBlockNetworkImage();
        } else {
            ret = internal.getBlockNetworkImage();
        }
        
        return ret;
    }

    private ReflectMethod getBlockNetworkImageMethod = new ReflectMethod(null, "getBlockNetworkImage");

    @Override
    public boolean getJavaScriptEnabled() {
        if (getJavaScriptEnabledMethod == null || getJavaScriptEnabledMethod.isNull()) {
            return getJavaScriptEnabledSuper();
        } else {
            return (Boolean)getJavaScriptEnabledMethod.invoke();
        }
    }

    public boolean getJavaScriptEnabledSuper() {
        boolean ret;
        if (internal == null) {
            ret = super.getJavaScriptEnabled();
        } else {
            ret = internal.getJavaScriptEnabled();
        }
        
        return ret;
    }

    private ReflectMethod getJavaScriptEnabledMethod = new ReflectMethod(null, "getJavaScriptEnabled");

    @Override
    public boolean getAllowUniversalAccessFromFileURLs() {
        if (getAllowUniversalAccessFromFileURLsMethod == null || getAllowUniversalAccessFromFileURLsMethod.isNull()) {
            return getAllowUniversalAccessFromFileURLsSuper();
        } else {
            return (Boolean)getAllowUniversalAccessFromFileURLsMethod.invoke();
        }
    }

    public boolean getAllowUniversalAccessFromFileURLsSuper() {
        boolean ret;
        if (internal == null) {
            ret = super.getAllowUniversalAccessFromFileURLs();
        } else {
            ret = internal.getAllowUniversalAccessFromFileURLs();
        }
        
        return ret;
    }

    private ReflectMethod getAllowUniversalAccessFromFileURLsMethod = new ReflectMethod(null, "getAllowUniversalAccessFromFileURLs");

    @Override
    public boolean getAllowFileAccessFromFileURLs() {
        if (getAllowFileAccessFromFileURLsMethod == null || getAllowFileAccessFromFileURLsMethod.isNull()) {
            return getAllowFileAccessFromFileURLsSuper();
        } else {
            return (Boolean)getAllowFileAccessFromFileURLsMethod.invoke();
        }
    }

    public boolean getAllowFileAccessFromFileURLsSuper() {
        boolean ret;
        if (internal == null) {
            ret = super.getAllowFileAccessFromFileURLs();
        } else {
            ret = internal.getAllowFileAccessFromFileURLs();
        }
        
        return ret;
    }

    private ReflectMethod getAllowFileAccessFromFileURLsMethod = new ReflectMethod(null, "getAllowFileAccessFromFileURLs");

    @Override
    public void setJavaScriptCanOpenWindowsAutomatically(boolean flag) {
        if (setJavaScriptCanOpenWindowsAutomaticallybooleanMethod == null || setJavaScriptCanOpenWindowsAutomaticallybooleanMethod.isNull()) {
            setJavaScriptCanOpenWindowsAutomaticallySuper(flag);
        } else {
            setJavaScriptCanOpenWindowsAutomaticallybooleanMethod.invoke(flag);
        }
    }

    public void setJavaScriptCanOpenWindowsAutomaticallySuper(boolean flag) {
        if (internal == null) {
            super.setJavaScriptCanOpenWindowsAutomatically(flag);
        } else {
            internal.setJavaScriptCanOpenWindowsAutomatically(flag);
        }
    }

    private ReflectMethod setJavaScriptCanOpenWindowsAutomaticallybooleanMethod = new ReflectMethod(null, "setJavaScriptCanOpenWindowsAutomatically");

    @Override
    public boolean getJavaScriptCanOpenWindowsAutomatically() {
        if (getJavaScriptCanOpenWindowsAutomaticallyMethod == null || getJavaScriptCanOpenWindowsAutomaticallyMethod.isNull()) {
            return getJavaScriptCanOpenWindowsAutomaticallySuper();
        } else {
            return (Boolean)getJavaScriptCanOpenWindowsAutomaticallyMethod.invoke();
        }
    }

    public boolean getJavaScriptCanOpenWindowsAutomaticallySuper() {
        boolean ret;
        if (internal == null) {
            ret = super.getJavaScriptCanOpenWindowsAutomatically();
        } else {
            ret = internal.getJavaScriptCanOpenWindowsAutomatically();
        }
        
        return ret;
    }

    private ReflectMethod getJavaScriptCanOpenWindowsAutomaticallyMethod = new ReflectMethod(null, "getJavaScriptCanOpenWindowsAutomatically");

    @Override
    public void setSupportMultipleWindows(boolean support) {
        if (setSupportMultipleWindowsbooleanMethod == null || setSupportMultipleWindowsbooleanMethod.isNull()) {
            setSupportMultipleWindowsSuper(support);
        } else {
            setSupportMultipleWindowsbooleanMethod.invoke(support);
        }
    }

    public void setSupportMultipleWindowsSuper(boolean support) {
        if (internal == null) {
            super.setSupportMultipleWindows(support);
        } else {
            internal.setSupportMultipleWindows(support);
        }
    }

    private ReflectMethod setSupportMultipleWindowsbooleanMethod = new ReflectMethod(null, "setSupportMultipleWindows");

    @Override
    public boolean supportMultipleWindows() {
        if (supportMultipleWindowsMethod == null || supportMultipleWindowsMethod.isNull()) {
            return supportMultipleWindowsSuper();
        } else {
            return (Boolean)supportMultipleWindowsMethod.invoke();
        }
    }

    public boolean supportMultipleWindowsSuper() {
        boolean ret;
        if (internal == null) {
            ret = super.supportMultipleWindows();
        } else {
            ret = internal.supportMultipleWindows();
        }
        
        return ret;
    }

    private ReflectMethod supportMultipleWindowsMethod = new ReflectMethod(null, "supportMultipleWindows");

    @Override
    public void setUseWideViewPort(boolean use) {
        if (setUseWideViewPortbooleanMethod == null || setUseWideViewPortbooleanMethod.isNull()) {
            setUseWideViewPortSuper(use);
        } else {
            setUseWideViewPortbooleanMethod.invoke(use);
        }
    }

    public void setUseWideViewPortSuper(boolean use) {
        if (internal == null) {
            super.setUseWideViewPort(use);
        } else {
            internal.setUseWideViewPort(use);
        }
    }

    private ReflectMethod setUseWideViewPortbooleanMethod = new ReflectMethod(null, "setUseWideViewPort");

    @Override
    public boolean getUseWideViewPort() {
        if (getUseWideViewPortMethod == null || getUseWideViewPortMethod.isNull()) {
            return getUseWideViewPortSuper();
        } else {
            return (Boolean)getUseWideViewPortMethod.invoke();
        }
    }

    public boolean getUseWideViewPortSuper() {
        boolean ret;
        if (internal == null) {
            ret = super.getUseWideViewPort();
        } else {
            ret = internal.getUseWideViewPort();
        }
        
        return ret;
    }

    private ReflectMethod getUseWideViewPortMethod = new ReflectMethod(null, "getUseWideViewPort");

    @Override
    public void setDomStorageEnabled(boolean flag) {
        if (setDomStorageEnabledbooleanMethod == null || setDomStorageEnabledbooleanMethod.isNull()) {
            setDomStorageEnabledSuper(flag);
        } else {
            setDomStorageEnabledbooleanMethod.invoke(flag);
        }
    }

    public void setDomStorageEnabledSuper(boolean flag) {
        if (internal == null) {
            super.setDomStorageEnabled(flag);
        } else {
            internal.setDomStorageEnabled(flag);
        }
    }

    private ReflectMethod setDomStorageEnabledbooleanMethod = new ReflectMethod(null, "setDomStorageEnabled");

    @Override
    public boolean getDomStorageEnabled() {
        if (getDomStorageEnabledMethod == null || getDomStorageEnabledMethod.isNull()) {
            return getDomStorageEnabledSuper();
        } else {
            return (Boolean)getDomStorageEnabledMethod.invoke();
        }
    }

    public boolean getDomStorageEnabledSuper() {
        boolean ret;
        if (internal == null) {
            ret = super.getDomStorageEnabled();
        } else {
            ret = internal.getDomStorageEnabled();
        }
        
        return ret;
    }

    private ReflectMethod getDomStorageEnabledMethod = new ReflectMethod(null, "getDomStorageEnabled");

    @Override
    public void setDatabaseEnabled(boolean flag) {
        if (setDatabaseEnabledbooleanMethod == null || setDatabaseEnabledbooleanMethod.isNull()) {
            setDatabaseEnabledSuper(flag);
        } else {
            setDatabaseEnabledbooleanMethod.invoke(flag);
        }
    }

    public void setDatabaseEnabledSuper(boolean flag) {
        if (internal == null) {
            super.setDatabaseEnabled(flag);
        } else {
            internal.setDatabaseEnabled(flag);
        }
    }

    private ReflectMethod setDatabaseEnabledbooleanMethod = new ReflectMethod(null, "setDatabaseEnabled");

    @Override
    public boolean getDatabaseEnabled() {
        if (getDatabaseEnabledMethod == null || getDatabaseEnabledMethod.isNull()) {
            return getDatabaseEnabledSuper();
        } else {
            return (Boolean)getDatabaseEnabledMethod.invoke();
        }
    }

    public boolean getDatabaseEnabledSuper() {
        boolean ret;
        if (internal == null) {
            ret = super.getDatabaseEnabled();
        } else {
            ret = internal.getDatabaseEnabled();
        }
        
        return ret;
    }

    private ReflectMethod getDatabaseEnabledMethod = new ReflectMethod(null, "getDatabaseEnabled");

    @Override
    public void setMediaPlaybackRequiresUserGesture(boolean require) {
        if (setMediaPlaybackRequiresUserGesturebooleanMethod == null || setMediaPlaybackRequiresUserGesturebooleanMethod.isNull()) {
            setMediaPlaybackRequiresUserGestureSuper(require);
        } else {
            setMediaPlaybackRequiresUserGesturebooleanMethod.invoke(require);
        }
    }

    public void setMediaPlaybackRequiresUserGestureSuper(boolean require) {
        if (internal == null) {
            super.setMediaPlaybackRequiresUserGesture(require);
        } else {
            internal.setMediaPlaybackRequiresUserGesture(require);
        }
    }

    private ReflectMethod setMediaPlaybackRequiresUserGesturebooleanMethod = new ReflectMethod(null, "setMediaPlaybackRequiresUserGesture");

    @Override
    public boolean getMediaPlaybackRequiresUserGesture() {
        if (getMediaPlaybackRequiresUserGestureMethod == null || getMediaPlaybackRequiresUserGestureMethod.isNull()) {
            return getMediaPlaybackRequiresUserGestureSuper();
        } else {
            return (Boolean)getMediaPlaybackRequiresUserGestureMethod.invoke();
        }
    }

    public boolean getMediaPlaybackRequiresUserGestureSuper() {
        boolean ret;
        if (internal == null) {
            ret = super.getMediaPlaybackRequiresUserGesture();
        } else {
            ret = internal.getMediaPlaybackRequiresUserGesture();
        }
        
        return ret;
    }

    private ReflectMethod getMediaPlaybackRequiresUserGestureMethod = new ReflectMethod(null, "getMediaPlaybackRequiresUserGesture");

    @Override
    public void setUserAgentString(String userAgent) {
        if (setUserAgentStringStringMethod == null || setUserAgentStringStringMethod.isNull()) {
            setUserAgentStringSuper(userAgent);
        } else {
            setUserAgentStringStringMethod.invoke(userAgent);
        }
    }

    public void setUserAgentStringSuper(String userAgent) {
        if (internal == null) {
            super.setUserAgentString(userAgent);
        } else {
            internal.setUserAgentString(userAgent);
        }
    }

    private ReflectMethod setUserAgentStringStringMethod = new ReflectMethod(null, "setUserAgentString");

    @Override
    public String getUserAgentString() {
        if (getUserAgentStringMethod == null || getUserAgentStringMethod.isNull()) {
            return getUserAgentStringSuper();
        } else {
            return (String)getUserAgentStringMethod.invoke();
        }
    }

    public String getUserAgentStringSuper() {
        String ret;
        if (internal == null) {
            ret = super.getUserAgentString();
        } else {
            ret = internal.getUserAgentString();
        }
        if (ret == null) return null;
        return ret;
    }

    private ReflectMethod getUserAgentStringMethod = new ReflectMethod(null, "getUserAgentString");

    @Override
    public void setAcceptLanguages(final String acceptLanguages) {
        if (setAcceptLanguagesStringMethod == null || setAcceptLanguagesStringMethod.isNull()) {
            setAcceptLanguagesSuper(acceptLanguages);
        } else {
            setAcceptLanguagesStringMethod.invoke(acceptLanguages);
        }
    }

    public void setAcceptLanguagesSuper(final String acceptLanguages) {
        if (internal == null) {
            super.setAcceptLanguages(acceptLanguages);
        } else {
            internal.setAcceptLanguages(acceptLanguages);
        }
    }

    private ReflectMethod setAcceptLanguagesStringMethod = new ReflectMethod(null, "setAcceptLanguages");

    @Override
    public String getAcceptLanguages() {
        if (getAcceptLanguagesMethod == null || getAcceptLanguagesMethod.isNull()) {
            return getAcceptLanguagesSuper();
        } else {
            return (String)getAcceptLanguagesMethod.invoke();
        }
    }

    public String getAcceptLanguagesSuper() {
        String ret;
        if (internal == null) {
            ret = super.getAcceptLanguages();
        } else {
            ret = internal.getAcceptLanguages();
        }
        if (ret == null) return null;
        return ret;
    }

    private ReflectMethod getAcceptLanguagesMethod = new ReflectMethod(null, "getAcceptLanguages");

    @Override
    public void setSaveFormData(final boolean enable) {
        if (setSaveFormDatabooleanMethod == null || setSaveFormDatabooleanMethod.isNull()) {
            setSaveFormDataSuper(enable);
        } else {
            setSaveFormDatabooleanMethod.invoke(enable);
        }
    }

    public void setSaveFormDataSuper(final boolean enable) {
        if (internal == null) {
            super.setSaveFormData(enable);
        } else {
            internal.setSaveFormData(enable);
        }
    }

    private ReflectMethod setSaveFormDatabooleanMethod = new ReflectMethod(null, "setSaveFormData");

    @Override
    public boolean getSaveFormData() {
        if (getSaveFormDataMethod == null || getSaveFormDataMethod.isNull()) {
            return getSaveFormDataSuper();
        } else {
            return (Boolean)getSaveFormDataMethod.invoke();
        }
    }

    public boolean getSaveFormDataSuper() {
        boolean ret;
        if (internal == null) {
            ret = super.getSaveFormData();
        } else {
            ret = internal.getSaveFormData();
        }
        
        return ret;
    }

    private ReflectMethod getSaveFormDataMethod = new ReflectMethod(null, "getSaveFormData");

    @Override
    public void setInitialPageScale(final float scaleInPercent) {
        if (setInitialPageScalefloatMethod == null || setInitialPageScalefloatMethod.isNull()) {
            setInitialPageScaleSuper(scaleInPercent);
        } else {
            setInitialPageScalefloatMethod.invoke(scaleInPercent);
        }
    }

    public void setInitialPageScaleSuper(final float scaleInPercent) {
        if (internal == null) {
            super.setInitialPageScale(scaleInPercent);
        } else {
            internal.setInitialPageScale(scaleInPercent);
        }
    }

    private ReflectMethod setInitialPageScalefloatMethod = new ReflectMethod(null, "setInitialPageScale");

    @Override
    public void setTextZoom(final int textZoom) {
        if (setTextZoomintMethod == null || setTextZoomintMethod.isNull()) {
            setTextZoomSuper(textZoom);
        } else {
            setTextZoomintMethod.invoke(textZoom);
        }
    }

    public void setTextZoomSuper(final int textZoom) {
        if (internal == null) {
            super.setTextZoom(textZoom);
        } else {
            internal.setTextZoom(textZoom);
        }
    }

    private ReflectMethod setTextZoomintMethod = new ReflectMethod(null, "setTextZoom");

    @Override
    public int getTextZoom() {
        if (getTextZoomMethod == null || getTextZoomMethod.isNull()) {
            return getTextZoomSuper();
        } else {
            return (Integer)getTextZoomMethod.invoke();
        }
    }

    public int getTextZoomSuper() {
        int ret;
        if (internal == null) {
            ret = super.getTextZoom();
        } else {
            ret = internal.getTextZoom();
        }
        
        return ret;
    }

    private ReflectMethod getTextZoomMethod = new ReflectMethod(null, "getTextZoom");

    @Override
    public void setDefaultFontSize(int size) {
        if (setDefaultFontSizeintMethod == null || setDefaultFontSizeintMethod.isNull()) {
            setDefaultFontSizeSuper(size);
        } else {
            setDefaultFontSizeintMethod.invoke(size);
        }
    }

    public void setDefaultFontSizeSuper(int size) {
        if (internal == null) {
            super.setDefaultFontSize(size);
        } else {
            internal.setDefaultFontSize(size);
        }
    }

    private ReflectMethod setDefaultFontSizeintMethod = new ReflectMethod(null, "setDefaultFontSize");

    @Override
    public int getDefaultFontSize() {
        if (getDefaultFontSizeMethod == null || getDefaultFontSizeMethod.isNull()) {
            return getDefaultFontSizeSuper();
        } else {
            return (Integer)getDefaultFontSizeMethod.invoke();
        }
    }

    public int getDefaultFontSizeSuper() {
        int ret;
        if (internal == null) {
            ret = super.getDefaultFontSize();
        } else {
            ret = internal.getDefaultFontSize();
        }
        
        return ret;
    }

    private ReflectMethod getDefaultFontSizeMethod = new ReflectMethod(null, "getDefaultFontSize");

    @Override
    public void setDefaultFixedFontSize(int size) {
        if (setDefaultFixedFontSizeintMethod == null || setDefaultFixedFontSizeintMethod.isNull()) {
            setDefaultFixedFontSizeSuper(size);
        } else {
            setDefaultFixedFontSizeintMethod.invoke(size);
        }
    }

    public void setDefaultFixedFontSizeSuper(int size) {
        if (internal == null) {
            super.setDefaultFixedFontSize(size);
        } else {
            internal.setDefaultFixedFontSize(size);
        }
    }

    private ReflectMethod setDefaultFixedFontSizeintMethod = new ReflectMethod(null, "setDefaultFixedFontSize");

    @Override
    public int getDefaultFixedFontSize() {
        if (getDefaultFixedFontSizeMethod == null || getDefaultFixedFontSizeMethod.isNull()) {
            return getDefaultFixedFontSizeSuper();
        } else {
            return (Integer)getDefaultFixedFontSizeMethod.invoke();
        }
    }

    public int getDefaultFixedFontSizeSuper() {
        int ret;
        if (internal == null) {
            ret = super.getDefaultFixedFontSize();
        } else {
            ret = internal.getDefaultFixedFontSize();
        }
        
        return ret;
    }

    private ReflectMethod getDefaultFixedFontSizeMethod = new ReflectMethod(null, "getDefaultFixedFontSize");

    @Override
    public void setSupportZoom(boolean support) {
        if (setSupportZoombooleanMethod == null || setSupportZoombooleanMethod.isNull()) {
            setSupportZoomSuper(support);
        } else {
            setSupportZoombooleanMethod.invoke(support);
        }
    }

    public void setSupportZoomSuper(boolean support) {
        if (internal == null) {
            super.setSupportZoom(support);
        } else {
            internal.setSupportZoom(support);
        }
    }

    private ReflectMethod setSupportZoombooleanMethod = new ReflectMethod(null, "setSupportZoom");

    @Override
    public boolean supportZoom() {
        if (supportZoomMethod == null || supportZoomMethod.isNull()) {
            return supportZoomSuper();
        } else {
            return (Boolean)supportZoomMethod.invoke();
        }
    }

    public boolean supportZoomSuper() {
        boolean ret;
        if (internal == null) {
            ret = super.supportZoom();
        } else {
            ret = internal.supportZoom();
        }
        
        return ret;
    }

    private ReflectMethod supportZoomMethod = new ReflectMethod(null, "supportZoom");

    @Override
    public void setBuiltInZoomControls(boolean enabled) {
        if (setBuiltInZoomControlsbooleanMethod == null || setBuiltInZoomControlsbooleanMethod.isNull()) {
            setBuiltInZoomControlsSuper(enabled);
        } else {
            setBuiltInZoomControlsbooleanMethod.invoke(enabled);
        }
    }

    public void setBuiltInZoomControlsSuper(boolean enabled) {
        if (internal == null) {
            super.setBuiltInZoomControls(enabled);
        } else {
            internal.setBuiltInZoomControls(enabled);
        }
    }

    private ReflectMethod setBuiltInZoomControlsbooleanMethod = new ReflectMethod(null, "setBuiltInZoomControls");

    @Override
    public boolean getBuiltInZoomControls() {
        if (getBuiltInZoomControlsMethod == null || getBuiltInZoomControlsMethod.isNull()) {
            return getBuiltInZoomControlsSuper();
        } else {
            return (Boolean)getBuiltInZoomControlsMethod.invoke();
        }
    }

    public boolean getBuiltInZoomControlsSuper() {
        boolean ret;
        if (internal == null) {
            ret = super.getBuiltInZoomControls();
        } else {
            ret = internal.getBuiltInZoomControls();
        }
        
        return ret;
    }

    private ReflectMethod getBuiltInZoomControlsMethod = new ReflectMethod(null, "getBuiltInZoomControls");

    @Override
    public boolean supportsMultiTouchZoomForTest() {
        if (supportsMultiTouchZoomForTestMethod == null || supportsMultiTouchZoomForTestMethod.isNull()) {
            return supportsMultiTouchZoomForTestSuper();
        } else {
            return (Boolean)supportsMultiTouchZoomForTestMethod.invoke();
        }
    }

    public boolean supportsMultiTouchZoomForTestSuper() {
        boolean ret;
        if (internal == null) {
            ret = super.supportsMultiTouchZoomForTest();
        } else {
            ret = internal.supportsMultiTouchZoomForTest();
        }
        
        return ret;
    }

    private ReflectMethod supportsMultiTouchZoomForTestMethod = new ReflectMethod(null, "supportsMultiTouchZoomForTest");

    @Override
    public void setSupportSpatialNavigation(boolean enable) {
        if (setSupportSpatialNavigationbooleanMethod == null || setSupportSpatialNavigationbooleanMethod.isNull()) {
            setSupportSpatialNavigationSuper(enable);
        } else {
            setSupportSpatialNavigationbooleanMethod.invoke(enable);
        }
    }

    public void setSupportSpatialNavigationSuper(boolean enable) {
        if (internal == null) {
            super.setSupportSpatialNavigation(enable);
        } else {
            internal.setSupportSpatialNavigation(enable);
        }
    }

    private ReflectMethod setSupportSpatialNavigationbooleanMethod = new ReflectMethod(null, "setSupportSpatialNavigation");

    @Override
    public boolean getSupportSpatialNavigation() {
        if (getSupportSpatialNavigationMethod == null || getSupportSpatialNavigationMethod.isNull()) {
            return getSupportSpatialNavigationSuper();
        } else {
            return (Boolean)getSupportSpatialNavigationMethod.invoke();
        }
    }

    public boolean getSupportSpatialNavigationSuper() {
        boolean ret;
        if (internal == null) {
            ret = super.getSupportSpatialNavigation();
        } else {
            ret = internal.getSupportSpatialNavigation();
        }
        
        return ret;
    }

    private ReflectMethod getSupportSpatialNavigationMethod = new ReflectMethod(null, "getSupportSpatialNavigation");

    @Override
    public void setSupportQuirksMode(boolean enable) {
        if (setSupportQuirksModebooleanMethod == null || setSupportQuirksModebooleanMethod.isNull()) {
            setSupportQuirksModeSuper(enable);
        } else {
            setSupportQuirksModebooleanMethod.invoke(enable);
        }
    }

    public void setSupportQuirksModeSuper(boolean enable) {
        if (internal == null) {
            super.setSupportQuirksMode(enable);
        } else {
            internal.setSupportQuirksMode(enable);
        }
    }

    private ReflectMethod setSupportQuirksModebooleanMethod = new ReflectMethod(null, "setSupportQuirksMode");

    @Override
    public boolean getSupportQuirksMode() {
        if (getSupportQuirksModeMethod == null || getSupportQuirksModeMethod.isNull()) {
            return getSupportQuirksModeSuper();
        } else {
            return (Boolean)getSupportQuirksModeMethod.invoke();
        }
    }

    public boolean getSupportQuirksModeSuper() {
        boolean ret;
        if (internal == null) {
            ret = super.getSupportQuirksMode();
        } else {
            ret = internal.getSupportQuirksMode();
        }
        
        return ret;
    }

    private ReflectMethod getSupportQuirksModeMethod = new ReflectMethod(null, "getSupportQuirksMode");

    @Override
    public void setLayoutAlgorithm(LayoutAlgorithmInternal la) {
        if (setLayoutAlgorithmLayoutAlgorithmInternalMethod == null || setLayoutAlgorithmLayoutAlgorithmInternalMethod.isNull()) {
            setLayoutAlgorithmSuper(la);
        } else {
            setLayoutAlgorithmLayoutAlgorithmInternalMethod.invoke(ConvertLayoutAlgorithmInternal(la));
        }
    }

    public void setLayoutAlgorithmSuper(LayoutAlgorithmInternal la) {
        if (internal == null) {
            super.setLayoutAlgorithm(la);
        } else {
            internal.setLayoutAlgorithm(la);
        }
    }

    private ReflectMethod setLayoutAlgorithmLayoutAlgorithmInternalMethod = new ReflectMethod(null, "setLayoutAlgorithm");

    @Override
    public LayoutAlgorithmInternal getLayoutAlgorithm() {
        if (getLayoutAlgorithmMethod == null || getLayoutAlgorithmMethod.isNull()) {
            return getLayoutAlgorithmSuper();
        } else {
            return (LayoutAlgorithmInternal)getLayoutAlgorithmMethod.invoke();
        }
    }

    public LayoutAlgorithmInternal getLayoutAlgorithmSuper() {
        LayoutAlgorithmInternal ret;
        if (internal == null) {
            ret = super.getLayoutAlgorithm();
        } else {
            ret = internal.getLayoutAlgorithm();
        }
        if (ret == null) return null;
        return ret;
    }

    private ReflectMethod getLayoutAlgorithmMethod = new ReflectMethod(null, "getLayoutAlgorithm");

    @Override
    public void setLoadWithOverviewMode(boolean overview) {
        if (setLoadWithOverviewModebooleanMethod == null || setLoadWithOverviewModebooleanMethod.isNull()) {
            setLoadWithOverviewModeSuper(overview);
        } else {
            setLoadWithOverviewModebooleanMethod.invoke(overview);
        }
    }

    public void setLoadWithOverviewModeSuper(boolean overview) {
        if (internal == null) {
            super.setLoadWithOverviewMode(overview);
        } else {
            internal.setLoadWithOverviewMode(overview);
        }
    }

    private ReflectMethod setLoadWithOverviewModebooleanMethod = new ReflectMethod(null, "setLoadWithOverviewMode");

    @Override
    public boolean getLoadWithOverviewMode() {
        if (getLoadWithOverviewModeMethod == null || getLoadWithOverviewModeMethod.isNull()) {
            return getLoadWithOverviewModeSuper();
        } else {
            return (Boolean)getLoadWithOverviewModeMethod.invoke();
        }
    }

    public boolean getLoadWithOverviewModeSuper() {
        boolean ret;
        if (internal == null) {
            ret = super.getLoadWithOverviewMode();
        } else {
            ret = internal.getLoadWithOverviewMode();
        }
        
        return ret;
    }

    private ReflectMethod getLoadWithOverviewModeMethod = new ReflectMethod(null, "getLoadWithOverviewMode");


    void reflectionInit() {
        coreBridge = XWalkCoreBridge.getInstance();
        if (coreBridge == null) return;

        ReflectConstructor constructor = new ReflectConstructor(
                coreBridge.getWrapperClass("XWalkSettings"), Object.class);
        try {
            wrapper = constructor.newInstance(this);
        } catch (UnsupportedOperationException e) {
            return;
        }

        enumLayoutAlgorithmClassValueOfMethod.init(null,
                coreBridge.getWrapperClass("XWalkSettings$LayoutAlgorithm"), "valueOf", String.class);

        setCacheModeintMethod.init(wrapper, null,
                "setCacheMode", int.class);
        getCacheModeMethod.init(wrapper, null,
                "getCacheMode");
        setBlockNetworkLoadsbooleanMethod.init(wrapper, null,
                "setBlockNetworkLoads", boolean.class);
        getBlockNetworkLoadsMethod.init(wrapper, null,
                "getBlockNetworkLoads");
        setAllowFileAccessbooleanMethod.init(wrapper, null,
                "setAllowFileAccess", boolean.class);
        getAllowFileAccessMethod.init(wrapper, null,
                "getAllowFileAccess");
        setAllowContentAccessbooleanMethod.init(wrapper, null,
                "setAllowContentAccess", boolean.class);
        getAllowContentAccessMethod.init(wrapper, null,
                "getAllowContentAccess");
        setJavaScriptEnabledbooleanMethod.init(wrapper, null,
                "setJavaScriptEnabled", boolean.class);
        setAllowUniversalAccessFromFileURLsbooleanMethod.init(wrapper, null,
                "setAllowUniversalAccessFromFileURLs", boolean.class);
        setAllowFileAccessFromFileURLsbooleanMethod.init(wrapper, null,
                "setAllowFileAccessFromFileURLs", boolean.class);
        setLoadsImagesAutomaticallybooleanMethod.init(wrapper, null,
                "setLoadsImagesAutomatically", boolean.class);
        getLoadsImagesAutomaticallyMethod.init(wrapper, null,
                "getLoadsImagesAutomatically");
        setBlockNetworkImagebooleanMethod.init(wrapper, null,
                "setBlockNetworkImage", boolean.class);
        getBlockNetworkImageMethod.init(wrapper, null,
                "getBlockNetworkImage");
        getJavaScriptEnabledMethod.init(wrapper, null,
                "getJavaScriptEnabled");
        getAllowUniversalAccessFromFileURLsMethod.init(wrapper, null,
                "getAllowUniversalAccessFromFileURLs");
        getAllowFileAccessFromFileURLsMethod.init(wrapper, null,
                "getAllowFileAccessFromFileURLs");
        setJavaScriptCanOpenWindowsAutomaticallybooleanMethod.init(wrapper, null,
                "setJavaScriptCanOpenWindowsAutomatically", boolean.class);
        getJavaScriptCanOpenWindowsAutomaticallyMethod.init(wrapper, null,
                "getJavaScriptCanOpenWindowsAutomatically");
        setSupportMultipleWindowsbooleanMethod.init(wrapper, null,
                "setSupportMultipleWindows", boolean.class);
        supportMultipleWindowsMethod.init(wrapper, null,
                "supportMultipleWindows");
        setUseWideViewPortbooleanMethod.init(wrapper, null,
                "setUseWideViewPort", boolean.class);
        getUseWideViewPortMethod.init(wrapper, null,
                "getUseWideViewPort");
        setDomStorageEnabledbooleanMethod.init(wrapper, null,
                "setDomStorageEnabled", boolean.class);
        getDomStorageEnabledMethod.init(wrapper, null,
                "getDomStorageEnabled");
        setDatabaseEnabledbooleanMethod.init(wrapper, null,
                "setDatabaseEnabled", boolean.class);
        getDatabaseEnabledMethod.init(wrapper, null,
                "getDatabaseEnabled");
        setMediaPlaybackRequiresUserGesturebooleanMethod.init(wrapper, null,
                "setMediaPlaybackRequiresUserGesture", boolean.class);
        getMediaPlaybackRequiresUserGestureMethod.init(wrapper, null,
                "getMediaPlaybackRequiresUserGesture");
        setUserAgentStringStringMethod.init(wrapper, null,
                "setUserAgentString", String.class);
        getUserAgentStringMethod.init(wrapper, null,
                "getUserAgentString");
        setAcceptLanguagesStringMethod.init(wrapper, null,
                "setAcceptLanguages", String.class);
        getAcceptLanguagesMethod.init(wrapper, null,
                "getAcceptLanguages");
        setSaveFormDatabooleanMethod.init(wrapper, null,
                "setSaveFormData", boolean.class);
        getSaveFormDataMethod.init(wrapper, null,
                "getSaveFormData");
        setInitialPageScalefloatMethod.init(wrapper, null,
                "setInitialPageScale", float.class);
        setTextZoomintMethod.init(wrapper, null,
                "setTextZoom", int.class);
        getTextZoomMethod.init(wrapper, null,
                "getTextZoom");
        setDefaultFontSizeintMethod.init(wrapper, null,
                "setDefaultFontSize", int.class);
        getDefaultFontSizeMethod.init(wrapper, null,
                "getDefaultFontSize");
        setDefaultFixedFontSizeintMethod.init(wrapper, null,
                "setDefaultFixedFontSize", int.class);
        getDefaultFixedFontSizeMethod.init(wrapper, null,
                "getDefaultFixedFontSize");
        setSupportZoombooleanMethod.init(wrapper, null,
                "setSupportZoom", boolean.class);
        supportZoomMethod.init(wrapper, null,
                "supportZoom");
        setBuiltInZoomControlsbooleanMethod.init(wrapper, null,
                "setBuiltInZoomControls", boolean.class);
        getBuiltInZoomControlsMethod.init(wrapper, null,
                "getBuiltInZoomControls");
        supportsMultiTouchZoomForTestMethod.init(wrapper, null,
                "supportsMultiTouchZoomForTest");
        setSupportSpatialNavigationbooleanMethod.init(wrapper, null,
                "setSupportSpatialNavigation", boolean.class);
        getSupportSpatialNavigationMethod.init(wrapper, null,
                "getSupportSpatialNavigation");
        setSupportQuirksModebooleanMethod.init(wrapper, null,
                "setSupportQuirksMode", boolean.class);
        getSupportQuirksModeMethod.init(wrapper, null,
                "getSupportQuirksMode");
        setLayoutAlgorithmLayoutAlgorithmInternalMethod.init(wrapper, null,
                "setLayoutAlgorithm", coreBridge.getWrapperClass("XWalkSettings$LayoutAlgorithm"));
        getLayoutAlgorithmMethod.init(wrapper, null,
                "getLayoutAlgorithm");
        setLoadWithOverviewModebooleanMethod.init(wrapper, null,
                "setLoadWithOverviewMode", boolean.class);
        getLoadWithOverviewModeMethod.init(wrapper, null,
                "getLoadWithOverviewMode");
    }
}
